package com.digdes.calendar.service.impl;

import com.digdes.calendar.dao.PlaceDAO;
import com.digdes.calendar.gwt.client.dto.PlaceDTOImpl;
import com.digdes.calendar.model.Place;
import com.digdes.calendar.service.PlaceService;

import java.util.HashSet;
import java.util.Set;

public class PlaceServiceImpl implements PlaceService{
    private PlaceDAO placeDAO;
    public Place place ;

    public void savePlace(Place place1){
        placeDAO.savePlace(place1);
    }


    public Set<PlaceDTOImpl> getAllPlace(){
        return makePlaceDtoSet(placeDAO.getAllPlace());
    }

    public static Set<PlaceDTOImpl> makePlaceDtoSet(Set<Place> places) {
        Set<PlaceDTOImpl> placesDto = new HashSet<PlaceDTOImpl>(0);

        for (Place e : places) {
            placesDto.add(makePlaceDto(e));
        }

        return placesDto;
    }
    public static PlaceDTOImpl makePlaceDto(Place place) {
        PlaceDTOImpl placeDto = new PlaceDTOImpl();

        //EventServiceImpl eventService = new EventServiceImpl();
        placeDto.setId(place.getId());
        placeDto.setAddress(place.getAddress());
        //placeDto.setEvents(eventService.makeEventDtoSet(place.getEvents()));

        return placeDto;
    }
    public PlaceDAO getPlaceDAO() {
        return placeDAO;
    }

    public void setPlaceDAO(PlaceDAO placeDAO) {
        this.placeDAO = placeDAO;
    }
    public Place getPlace() {
        return place;
    }

    public void setPlace(Place place) {
        this.place = place;
    }

}
